﻿namespace CodingExercises._11_20;

public class SeparateObjects
{
    // 对混合对象列表中分离字符串和整数
    public static (List<int> ints, List<string> strings, int unknownCount) Method(List<object> objects)
    {
        var integers = objects.OfType<int>().ToList();
        var strings = objects.OfType<string>().ToList();
        var unknownCount = objects.Count - integers.Count - strings.Count;
        return (integers, strings, unknownCount);
    }

    public static (List<int> ints, List<string> strings, int unknownCount) Method2(List<object> objects)
    {
        var integers = new List<int>();
        var strings = new List<string>();
        var unknownCount = 0;
        foreach (var item in objects)
        {
            if (item is int number)
            {
                integers.Add(number);
            }
            else if (item is string text)
            {
                strings.Add(text);
            }
            else
            {
                ++unknownCount;
            }
        }

        return (integers, strings, unknownCount);
    }
}